import pymysql
from pyecharts import options
from pyecharts.charts import Pie

db=pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    password="4416",
    charset="utf8",
    database="crawlerdemo"
)
cursor=db.cursor()
#用来查找岗位数量最多的五个城市
sql=("select job_place,count(job_id) from job group by job_place"
     " order by count(job_id) desc limit 5")
try:
    cursor.execute(sql)
    res=cursor.fetchall()
    pie=Pie()
    #[("类型1",30),("类型2",40),...]
    pie.add("单位/个",res)
    pie.set_global_opts(title_opts=options.TitleOpts(title="岗位数量最多的五个城市"))
    pie.render("pienum.html")
except Exception as e:
    print(e)
    print("查询出错了")